Imports DTO
Imports System.Data.OleDb
Public Class MonHocDAO
    Inherits AbstractDAO
    Public Function LayBang() As DataTable
        Dim dt As New DataTable()
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "select * from MonHoc"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Sub CapNhatBang(ByVal dt As DataTable)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from MonHoc"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)
        cn.Close()
    End Sub
    Public Function LayDanhSach() As IList
        Dim ds As New ArrayList()
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from MonHoc"
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            Dim mhDTO As New MonHocDTO
            mhDTO.MaMonHoc = dr("MaMonHoc")
            mhDTO.QuiDinhSoTietHocLienTiepToiDa = dr("QuiDinhSoTietHocLienTiepToiDa")
            mhDTO.QuiDinhSoTietHocLienTiepToiThieu = dr("QuiDinhSoTietHocLienTiepToiThieu")
            mhDTO.TenMonHoc = dr("TenMonHoc")
            ds.Add(mhDTO)
        End While
        dr.Close()
        cn.Close()
        Return ds
    End Function
    Public Function TiemKiemTheoMa(ByVal mamonhoc As String) As MonHocDTO
        Dim mhDTO As New MonHocDTO
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from PhanCong Where MaPhanCong = " & mamonhoc
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            mhDTO.MaMonHoc = dr("MaMonHoc")
            mhDTO.QuiDinhSoTietHocLienTiepToiDa = dr("QuiDinhSoTietHocLienTiepToiDa")
            mhDTO.QuiDinhSoTietHocLienTiepToiThieu = dr("QuiDinhSoTietHocLienTiepToiThieu")
            mhDTO.TenMonHoc = dr("TenMonHoc")

        End While
        dr.Close()
        cn.Close()
        Return mhDTO
    End Function
    Public Sub Them(ByVal mhDTO As MonHocDTO)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Insert into MonHoc(MaMonHoc, QuiDinhSoTietHocLienTiepToiDa, QuiDinhSoTietHocLienTiepToiThieu, TenMonHoc) value= " & _
        " ( '" & mhDTO.MaMonHoc & "', '" & mhDTO.QuiDinhSoTietHocLienTiepToiDa & "', '" & mhDTO.QuiDinhSoTietHocLienTiepToiThieu & "', '" & mhDTO.TenMonHoc & ")"
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        strSQL = "Select @@INDENTITY"
        cmd = New OleDbCommand(strSQL, cn)
        mhDTO.MaMonHoc = cmd.ExecuteScalar()
        cn.Close()
    End Sub
    Public Sub XoaTheoMa(ByVal mamonhoc As String)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Delete from PhanCong Where MaMonHoc= " & mamonhoc
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
End Class
